<?php
class Hotelscats_model extends CRM_Model{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function GetDS(){
		$this->db->select('_hotelscats.rid as rid, _hotelscats.code as code,
							_hotelscats.hotelcat_name as hotelcat_name,
							_hotelscats.modifyDT as modifyDT, 
							_hotelscats.descr as descr, _hotelscats.archive');
		$this->db->from('_hotelscats');
		if($sort = $this->ciObject->GetSessionData('sort')){
			$this->db->orderby($sort['c'], $sort['r']);
		}
		$query = $this->DBGet('_hotelscats');
		if($query->num_rows()>0) return $this->ciObject->GetPagingDS($query->result());
		return array();
	}
	
	public function GetEditDS(){
		$this->db->select('_hotelscats.rid as rid, _hotelscats.code as code,
							_hotelscats.hotelcat_name as hotelcat_name,
							_hotelscats.modifyDT as modifyDT, 
							_hotelscats.descr as descr, _hotelscats.archive');
		$this->db->from('_hotelscats');
		$this->db->where(array('rid'=>$this->ciObject->GetSessionData('activerecord')));
		$query = $this->DBGet('_hotelscats');
		if($query->num_rows()>0) return $query->row();
		return False;
	}
	
	public function CreateRecord(){
		$insArray = array('code'=>$_POST['code'],
							'hotelcat_name'=>$_POST['hotelcat_name'],
							'descr'=>$_POST['descr'],
							'archive'=>$_POST['archive'],
							'modifier_users_rid'=>$this->userRid,
							'modifyDT'=>$this->nowTime);
		$this->db->trans_begin();
		$this->db->insert('_hotelscats', $insArray);
		$insRid = $this->db->insert_id();
		if ($this->db->trans_status() === FALSE){
    		$this->db->trans_rollback();
    		return False;
		}else{
    		$this->db->trans_commit();
    		return $insRid;
		}		
	}
	
	public function UpdateRecord(){
		$updateArray = array('code'=>$_POST['code'],
							'hotelcat_name'=>$_POST['hotelcat_name'],
							'descr'=>$_POST['descr'],
							'archive'=>$_POST['archive'],
							'modifier_users_rid'=>$this->userRid,
							'modifyDT'=>$this->nowTime);
		$this->db->trans_begin();
		$this->db->update('_hotelscats', $updateArray, array('rid'=>$this->ciObject->GetSessionData('activerecord')));
		if ($this->db->trans_status() === FALSE){
    		$this->db->trans_rollback();
    		return False;
		}else{
    		$this->db->trans_commit();
    		return True;
		}		
	}
	
	public function DeleteRecord(){
		$this->db->trans_begin();
		$this->db->delete('_hotelscats', array('rid'=>$this->ciObject->GetSessionData('activerecord')));
		if ($this->db->trans_status() === FALSE){
    		$this->db->trans_rollback();
    		return False;
		}else{
    		$this->db->trans_commit();
    		return True;
		}		
	}
}
?>